package com.hcnow.common

import com.hcnow.common.Exception.AuthorizationException
import com.hcnow.common.utils.JWTUtils
import org.springframework.web.servlet.HandlerInterceptor
import org.springframework.web.servlet.ModelAndView
import java.lang.Exception
import javax.servlet.http.HttpServletRequest
import javax.servlet.http.HttpServletResponse

/**
 * 集成请求拦截器
 */
class IntegrateHttpInterceptor() : HandlerInterceptor {
    override fun preHandle(request: HttpServletRequest, response: HttpServletResponse, handler: Any?): Boolean {
        if(!JWTUtils.validateToken(request.getHeader("Authorization")))throw AuthorizationException("token is not valid");
        return true;
    }

    override fun postHandle(request: HttpServletRequest, response: HttpServletResponse, handler: Any?, modelAndView: ModelAndView?) {

    }

    override fun afterCompletion(request: HttpServletRequest, response: HttpServletResponse, handler: Any?, ex: Exception?) {

    }
}